#!/bin/bash
set -eo pipefail

echo "[DEPRECATED] This script is outdated and was originally for demo purposes. It will be removed soon."

NAME="$1"
TAG="$2"

# Place the app inside the container. If you already have app inside your tar, use /bin/bash -c "tar -x"
ID=$(cat | docker run -i -a stdin progrium/buildstep /bin/bash -c "mkdir -p /app && tar -xC /app")
test $(docker wait $ID) -eq 0
docker commit $ID $NAME $TAG > /dev/null

# Run the builder script and attach to view output
if [[ -z "$TAG" ]]; then
  IMAGE=$NAME
else
  IMAGE=$NAME:$TAG
fi
ID=$(docker run -d $IMAGE /build/builder)
docker attach $ID
test $(docker wait $ID) -eq 0
docker commit $ID $NAME $TAG > /dev/null
